West Coast Pest - active attendance stabilization patch
Date: 2026-04-10

This overwrite package focuses only on the live attendance flow and midnight auto-close.

Included fixes
1. api/clock-in.php
   - allows outside-radius clock-in
   - stores clock_in_status = OUTSIDE_RADIUS instead of rejecting
   - still blocks real invalid states only
   - auto-closes stale previous-day open sessions before checking today's open session
   - optionally writes CLOCK_IN event to work_session_events when that table exists

2. api/clock-out.php
   - allows outside-radius clock-out
   - stores clock_out_status = OUTSIDE_RADIUS instead of rejecting
   - optionally writes CLOCK_OUT event to work_session_events when that table exists

3. api/auto-close-sessions.php
   - rewritten to use PDO correctly
   - fixes the broken mysqli-based version that did not match api/db.php
   - sets:
     - clock_out_time = session_date + 1 day at 00:00:00
     - session_status = CLOSED
     - closed_by_type = auto
     - close_reason = Auto-closed at midnight
   - also fills system fields for consistency where columns exist

4. cron/auto-close-sessions.php
   - runs the same shared auto-close logic directly
   - logs success/failure to PHP error log

5. api/attendance-shared.php
   - shared helpers for schema checks, event logging, and auto-close logic

Recommended quick live checks after overwrite
- clock in inside radius -> should succeed with ON_SITE
- clock in outside radius -> should succeed with OUTSIDE_RADIUS
- clock out inside radius -> should succeed with ON_SITE
- clock out outside radius -> should succeed with OUTSIDE_RADIUS
- confirm backoffice Exceptions shows outside-radius rows
- run cron/auto-close-sessions.php manually once and confirm JSON/logged result
- verify old open sessions after midnight return zero rows
